<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org"
>

<head>

    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">

</head>
<style>
    .cx > div {
        margin-bottom: 10px;
    }
</style>
<body>

<div class="panel panel-default operation_dept" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" action="" lay-filter="deptInfo" style="width: 700px;margin-top: 10px">
            <input name="id" hidden/>
            <input name="aid" hidden/>
            <div class="layui-form-item">
                <label class="layui-form-label">企业名称</label>
                <div class="layui-input-block">
                    <input type="enterprise_name" name="enterprise_name" placeholder="请输入企业名称" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">统一社会信用代码</label>
                <div class="layui-input-block">
                    <input type="social_credit_code" name="social_credit_code" placeholder="请输入统一社会信用代码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">注册号</label>
                <div class="layui-input-block">
                    <input type="registration_number" name="registration_number" placeholder="请输入注册号" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label ">登记机关</div>
                <div class="layui-input-block">
                    <input type="registration_authority" name="registration_authority" placeholder="请选择登记机关"
                           autocomplete="off" class="layui-input"
                           style="background:#eeeeee!important">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label ">管辖机关</div>
                <div class="layui-input-block">
                    <input type="domination" name="domination" placeholder="请选择管辖机关" autocomplete="off"
                           class="layui-input"
                           style="background:#eeeeee!important">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">地址</label>
                <div class="layui-input-block">
                    <input type="address" name="address" placeholder="请输入地址" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label">联系电话</div>
                <div class="layui-input-block">
                    <input type="contact_number" name="contact_number" placeholder="请输入联系电话" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="enterprise_status" lay-skin="switch" lay-filter="jobSwitch"
                           lay-text="开业|关业" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label">联络员电话</div>
                <div class="layui-input-block">
                    <input type="liaison_man_name" name="liaison_man_name" placeholder="请输入联络员电话" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label">联络员手机号码</div>
                <div class="layui-input-block">
                    <input type="liaison_man_phone" name="liaison_man_phone" placeholder="请输入联络员手机号码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上报状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="report_status" lay-skin="switch" lay-filter="switch" lay-text="已上报|未上报"
                           checked>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="dept-table">
    <!--  ---------------------------------搜索条件  -->
    <div id="searchParam" shiro:hasPermission="sys:user:list">
        <div class="layui-form-item cx">
            <div class="layui-input-inline">
                <input type="text" id="enterprise_name" class="layui-input" autocomplete="off" placeholder="请输入企业名称">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="social_credit_code" class="layui-input" autocomplete="off"
                       placeholder="请输入统一社会信用代码">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="registration_number" class="layui-input" autocomplete="off" placeholder="请输入注册号">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="registration_authority" class="layui-input" autocomplete="off"
                       placeholder="请输入登录机关">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="domination" class="layui-input" autocomplete="off" placeholder="请输入管辖机关">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="address" class="layui-input" autocomplete="off" placeholder="请输入地址">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="contact_number" class="layui-input" autocomplete="off" placeholder="请输入联系电话">
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="date_of_establishment" placeholder="成立日期">
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="approval_date" placeholder="核准日期">
            </div>
            <div class="layui-input-inline layui-form">
                <input type="text" class="layui-input" id="enterprise_status" placeholder="请输入企业状态">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="liaison_man_name" class="layui-input" autocomplete="off" placeholder="请输入联络员姓名">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="liaison_man_phone" class="layui-input" autocomplete="off"
                       placeholder="请输入联络员手机号码">
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="create_time" placeholder="创建日期">
            </div>
            <div class="layui-input-inline layui-form">
                <select id="report_status">
                    <option value="0">请选择企业上报状态</option>
                    <option value="1">已上报</option>
                    <option value="2">未上报</option>
                </select>
            </div>
            <div class="layui-input-inline layui-form">
                <select id="enterprise_type">
                    <option value="0">请选择企业类型</option>
                    <option value="1">企业</option>
                    <option value="2">农合社</option>
                    <option value="3">个人</option>
                </select>
            </div>
            <div class="layui-input-inline layui-form">
                <select id="matching">
                    <option value="0">请选择匹配状态</option>
                    <option value="1">已匹配</option>
                    <option value="2">未匹配</option>
                </select>
            </div>
            <div class="layui-input-inline ">
                <button class="layui-btn" onclick="search()" id="search">查询</button>
            </div>
        </div>
    </div>
    <div class="upload-report" hidden>
        <div style="height: 40px;background-color: #009688">
            <span style="line-height: 40px;color: white;letter-spacing: 5px;margin-left: 5px">上报信息</span>
            <a class="layui-btn" href="javascript:;" onclick="uploadClose()" style="width: 40px;float: right">
                <i style="margin-right: -8px;" class="layui-icon layui-icon-close"></i>
            </a>
        </div>
        <div class="layui-input-inline layui-form" style="margin-top: 20px;margin-left: 25%;">
            <select id="report_status_excel">
                <option value="1">已上报</option>
                <option value="2">未上报</option>
            </select>
        </div>
        <div style="margin-left: 25%;margin-top: 20px;">
            <button style="width: 212px;height: 40px;letter-spacing: 5px;" class="layui-btn layui-btn-sm" shiro:hasPermission="rpt:annualReport:add" id="uploadAnnualExcel">选择文件</button>
        </div>

    </div>
    <!--  ------------------------------表格  -->
    <table class="layui-table" id="annualsTable" lay-filter="annualsTable"></table>
</div>
<div id="deptTree" style="display: none"></div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addDept" shiro:hasPermission="rpt:annualReport:add">添加
        </button>
        <button class="layui-btn layui-btn-sm" lay-event="batchDeleted" shiro:hasPermission="rpt:annualReport:del">删除
        </button>
        <button class="layui-btn layui-btn-sm" lay-event="batchMatching" shiro:hasPermission="rpt:annualReport:del">匹配
        </button>

        <button class="layui-btn layui-btn-sm" lay-event="downloadAnnual" style="float: right;margin-right: -118px;">下载</button>
        <button class="layui-btn layui-btn-sm" lay-event="uploadAnnual" id="uploadAnnual"
                style="float: right;margin-right: -64px;">上传
        </button>

    </div>

</script>
<script type="text/html" id="tool">
    <a shiro:hasPermission="rpt:annualReport:update" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a shiro:hasPermission="rpt:annualReport:del" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns2;
    var uploadIns;
    var table = layui.table;
    var upload = layui.upload;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var tree = layui.tree;
    var transfer = layui.transfer;
    var deptNo = null;
    var startDateOfEstablishment = null;
    var endDateOfEstablishment = null;
    var startApprovalDate = null;
    var endApprovalDate = null;
    var createStartTime = null;
    var createEndTime = null;
    layui.use(['table', 'layer', 'laydate', 'tree', 'transfer', 'upload'], function () {
        tableIns2 = table.render({
            elem: '#annualsTable'// 表格id
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/rpt/findAllAnnualReport' //数据接口
            , method: 'POST',
            toolbar: '#toolbar'
            , defaultToolbar: []
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                console.log(res);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data.list) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data.list) ? null : res.data.list //解析数据列表
                }
            },
            cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'enterpriseName', title: '企业名称', width: 150},
                    {field: 'socialCreditCode', title: '统一社会信用代码', width: 120},
                    {field: 'registrationNumber', title: '注册号', width: 120},
                    {field: 'registrationAuthority', title: '登录机关', width: 120},
                    {field: 'domination', title: '管辖机关', width: 120},
                    {field: 'address', title: '地址', width: 120},
                    {field: 'contactNumber', title: '联系电话', width: 100},
                    {
                        field: 'establishDate', title: '成立日期', width: 125, templet: function (item) {
                            return "<div>" + layui.util.toDateString(item.establishDate, 'yyyy年MM月dd日') + "</div>";
                        }
                    },
                    {
                        field: 'approvalDate', title: '核准日期', width: 125, templet: function (item) {
                            return "<div>" + layui.util.toDateString(item.approvalDate, 'yyyy年MM月dd日') + "</div>";
                        }
                    },
                    {field: 'enterpriseStatus', title: '状态', width: 60},
                    {field: 'liaisonManName', title: '联络员姓名', width: 80},
                    {field: 'liaisonManPhone', title: '联络员手机号码', width: 100},
                    {
                        field: 'createTime', title: '创建日期', width: 125, templet: function (item) {
                            return "<div>" + layui.util.toDateString(item.createTime, 'yyyy年MM月dd日') + "</div>";
                        }
                    },
                    {
                        field: 'reportStatus', title: '上报状态', width: 90, templet: function (item) {
                            if (item.reportStatus === 1 || item.reportStatus === "1") {
                                return '已上报';
                            }
                            if (item.reportStatus === 2 || item.reportStatus === "2") {
                                return '未上报';
                            }
                        }
                    },
                    {
                        field: 'enterpriseType', title: '企业类型', width: 90, templet: function (item) {
                            if (item.enterpriseType === 1 || item.enterpriseType === "1") {
                                return '企业';
                            }
                            if (item.enterpriseType === 2 || item.enterpriseType === "2") {
                                return '农合社';
                            }
                            if (item.enterpriseType === 3 || item.enterpriseType === "3") {
                                return '个人';
                            }
                        }
                    },
                    {
                        field: 'matching', title: '匹配状态', width: 90, templet: function (item) {
                            if (item.matching === 1 || item.matching === "1") {
                                return '已匹配';
                            }
                            if (item.matching === 2 || item.matching === "2") {
                                return '未匹配';
                            }
                        }
                    },
                    {title: '操作', minWidth: 120, toolbar: '#tool'}
                ]
            ]
        });

        //上传事件
        uploadIns = upload.render({
            elem: '#uploadAnnualExcel'
            , headers: {"authorization": token}
            , url: '/rpt/annualReportUploadExcel'
            , data: {"reportStatus" : $("#report_status_excel").val()}
            , size: '3072'
            , accept: 'file' //普通文件
            , exts: 'xlsx|xls' //允许上传的文件后缀
            , method: 'post'
            , done: function (res) { //返回值接收
                console.log(res);
                $(".upload-report").hide();
                // if (res.data != null){
                //     layer.open({
                //         type: 1,
                //         content: "上传成功！请选择" +
                //             "<select id='report_status'>" +
                //             "<option value='1'>已上报</option>" +
                //             "<option value='2'>未上报</option>" +
                //             "</select>",
                //         area: ['500px', '300px'],
                //         offset: 'auto',
                //         shade: 0.3,
                //         btn: ['提交'],
                //         yes: function (index, layero) {
                //             var annualReport = [];
                //                 // list: res.data
                //                 // reportStatus: $("#report_status").val()
                //             // };
                //
                //             for (var i = 0 ;i<res.data.length;i++) {
                //                 annualReport.push(res.data[i])
                //             }
                //             // var list = JSON.stringify(annualReport);
                //             console.log(annualReport);
                //             $.ajax({
                //                 url: 'http://192.168.0.87:8080/rpt/annualReportExcelSubmit',
                //                 type: 'post',
                //                 data: {"list":JSON.stringify(annualReport),"type": 1},
                //                 // contentType: 'application/json;charsetset=UTF-8',
                //                 dataType: 'json',
                //                 beforeSend: function(request) {
                //                     request.setRequestHeader("authorization", CoreUtil.getData("access_token"));
                //                 },
                //                 success: function (data) {
                //                     if (data.msg != null){
                //                         layer.msg('操作成功！');
                //                     }
                //                 }
                //             })
                //         }
                //     })
                //
                // }

                // if(res=="1"){
                //     layer.msg('导入成功！', {
                //     }, function(){
                //         location.reload();
                //     });
                // }else{
                //     layer.msg('导入失败！', {
                //     }, function(){
                //         location.reload();
                //     });
                // }
            }
        });

        //操作项事件
        table.on('tool(annualsTable)', function (obj) {
            console.log(obj, 111);
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    var annualIds = [];
                    annualIds.push(data.id);
                    tipDialog(annualIds, data.enterpriseName);
                    break;
                case 'edit':
                    $(".dept-table").hide();
                    $(".operation_dept").show();
                    $(".title").html("编辑企业");
                    $(".operation_dept input[name=id]").val(data.id);
                    $(".operation_dept input[name=enterprise_name]").val(data.enterpriseName);
                    $(".operation_dept input[name=social_credit_code]").val(data.socialCreditCode);
                    $(".operation_dept input[name=registration_number]").val(data.registrationNumber);
                    $(".operation_dept input[name=registration_authority]").val(data.registrationAuthority);
                    $(".operation_dept input[name=domination]").val(data.domination);
                    $(".operation_dept input[name=address]").val(data.address);
                    $(".operation_dept input[name=contact_number]").val(data.contactNumber);
                    // var xx = document.getElementsByClassName("layui-unselect layui-form-switch");
                    // console.log(xx);
                    if (data.enterpriseStatus == 1) {
                        $(".operation_dept input[name=enterprise_status]").attr('checked', 'checked');
                        $(".operation_dept input[name=enterprise_status]").attr('type', 'hidden').val(1);
                        var x = document.getElementsByClassName("layui-unselect layui-form-switch"); //获取选择框的内容
                        x[0].setAttribute("class", "layui-unselect layui-form-switch layui-form-onswitch"); //给选择框添加打开属性
                        var d = document.getElementsByTagName('em')[0];
                        d.firstChild.nodeValue = '开业';
                    } else {
                        console.log(data, 333);
                        $(".operation_dept input[name=enterprise_status]").attr('type', 'hidden').removeAttr("checked").val(0);
                        var x = document.getElementsByClassName("layui-unselect layui-form-switch");
                        x[0].setAttribute("class", "layui-unselect layui-form-switch");
                        var d = document.getElementsByTagName('em')[0];
                        d.firstChild.nodeValue = '关业';
                    }
                    $(".operation_dept input[name=liaison_man_name]").val(data.liaisonManName);
                    $(".operation_dept input[name=liaison_man_phone]").val(data.liaisonManPhone);
                    if (data.reportStatus == 1) {
                        $(".operation_dept input[name=report_status]").attr('checked', 'checked');
                        $(".operation_dept input[name=report_status]").attr('type', 'hidden').val(1);
                        var xx = document.getElementsByClassName("layui-unselect layui-form-switch");
                        xx[1].setAttribute("class", "layui-unselect layui-form-switch layui-form-onswitch");
                        var dd = document.getElementsByTagName('em')[1];
                        dd.firstChild.nodeValue = '已上报';
                    } else {
                        console.log(data, 222);
                        $(".operation_dept input[name=report_status]").attr('type', 'hidden').removeAttr("checked").val(0);
                        var xx = document.getElementsByClassName("layui-unselect layui-form-switch");
                        xx[1].setAttribute("class", "layui-unselect layui-form-switch");
                        var dd = document.getElementsByTagName('em')[1];
                        dd.firstChild.nodeValue = '未上报';
                    }
                    form.render(); //更新全部
                    initTree(data.id);
                    break;
            }
        });
        table.on('toolbar(annualsTable)', function (obj) {
            switch (obj.event) {
                case 'batchDeleted':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg("请选择要批量删除的企业");
                    } else {
                        var annualIds = [];
                        $(data).each(function (index, item) {
                            annualIds.push(item.id);
                        });
                        tipDialog(annualIds, "选中的");
                    }
                    break;
                case 'addDept':
                    selectNode = null;
                    $(".dept-table").hide();
                    $(".operation_dept").show();
                    $(".title").html("新增企业");
                    $(".operation_dept input[name=id]").val("");
                    $(".operation_dept input[name=enterprise_name]").val("");
                    $(".operation_dept input[name=social_credit_code]").val("");
                    $(".operation_dept input[name=registration_number]").val("");
                    $(".operation_dept input[name=registration_authority]").val("");
                    $(".operation_dept input[name=domination]").val("");
                    $(".operation_dept input[name=address]").val("");
                    $(".operation_dept input[name=contact_number]").val("");
                    $(".operation_dept input[name=enterprise_status]").attr('checked', 'checked');
                    $(".operation_dept input[name=enterprise_status]").attr('type', 'hidden').val(1);
                    $(".operation_dept input[name=liaison_man_name]").val("");
                    $(".operation_dept input[name=liaison_man_phone]").val("");
                    $(".operation_dept input[name=report_status]").attr('checked', 'checked');
                    $(".operation_dept input[name=report_status]").attr('type', 'hidden').val(1);
                    var x = document.getElementsByClassName("layui-unselect layui-form-switch");
                    x[0].setAttribute("class", "layui-unselect layui-form-switch layui-form-onswitch");
                    var d = document.getElementsByTagName('em')[0];
                    d.firstChild.nodeValue = '启用';
                    form.render(); //更新全部
                    initTree("");
                    break;
                case 'batchMatching':
                    matchingAnnual();
                    break;
                case 'uploadAnnual':
                    uploadAnnual();
                    break;
                case 'downloadAnnual':
                    downloadAnnual();
                    break;
            }
        });

        /**
         * 点击匹配事件
         */
        var matchingAnnual = function () {
            CoreUtil.sendGet("/clickMatching",{},function (res) {
                console.log(res);
                layer.msg(res.data);
            })
        }


        /**
        * 点击上传按钮弹出选择框
         * 选择框选择是否是上报状态
        */
        var uploadAnnual = function (){
            $(".upload-report").show();
        }



        /**
         * 下载按钮调用接口
         */
        var downloadAnnual = function () {

            $.ajax({
                type: "post", url: "/rpt/excel", data: {}, success: function (result) {
                    if (result.status == 0) {
                        window.open(result.data)
                    }
                    if (result.message != null) {
                        layer.msg(result.message)
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('{"status":"' + XMLHttpRequest.status + '","readyState":"' + XMLHttpRequest.readyState + '","textStatus":"' + textStatus + '","errorThrown":"' + errorThrown + '"}')
                }
            })



             // CoreUtil.sendPost("/rpt/excel", {}, function (res) {
             //     console.log(res);
             //     console.log("123");
             // });
             //    $.ajax({
             //        type:'post',
             //        url:'/rpt/excel',
             //        data:null,
             //        async:true,
             //        beforeSend: function(request) {
             //            request.setRequestHeader("authorization", CoreUtil.getData("access_token"));
             //        },
             //        success : function(msg){
             //            alert(msg);
             //        }
             //    })

        };

        /**
         * 批量删除和单个删除统一调用接口
         * @param annualIds 选择删除的id数组
         * @param enterpriseName 选择删除的id的企业名
         */
        var tipDialog = function (annualIds, enterpriseName) {
            layer.open({
                content: '确定要删除' + enterpriseName + "企业么?",
                yes: function (index, layero) {
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                    CoreUtil.sendDelete("/rpt/delAnnualReport", annualIds, function (res) {
                        layer.msg(res.msg);
                        search();
                    });
                }
            });
        };
        /**
         * 返回按钮
         */
        $("#btn_cancel").click(function () {
            $(".dept-table").show();
            $(".operation_dept").hide();
            return false;
        });
        /**
         * 设置树形数据
         */
        var loadDeptTree = function (data) {
            console.log(data, 123);
            tree.render({
                elem: '#deptTree'
                , data: data
                , onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
                , click: function (obj) {
                    selectNode = obj;
                    layer.msg(JSON.stringify(selectNode.data.title));
                }
            });
        };
        // $(".operation_dept input[name=registration_authority]").click(function () {
        //     layer.open({
        //         type: 1,
        //         skin: 'layui-layer-molv',
        //         title: "选择部门",
        //         area: ['400px', '450px'],
        //         shade: 0,
        //         shadeClose: false,
        //         content: jQuery("#deptTree"),
        //         btn: ['确定', '取消'],
        //         yes: function (index) {
        //             console.log(index,321);
        //             if (selectNode.data != null) {
        //                 //选中回显
        //                 $(".operation_dept input[name=aid]").val(selectNode.data.id);
        //                 $(".operation_dept input[name=registration_authority]").val(selectNode.data.title);
        //             }
        //
        //             layer.close(index);
        //         }
        //     });
        // });
        // $(".operation_dept input[name=domination]").click(function () {
        //     layer.open({
        //         type: 1,
        //         skin: 'layui-layer-molv',
        //         title: "选择部门",
        //         area: ['400px', '450px'],
        //         shade: 0,
        //         shadeClose: false,
        //         content: jQuery("#deptTree"),
        //         btn: ['确定', '取消'],
        //         yes: function (index) {
        //             if (selectNode.data != null) {
        //                 //选中回显
        //                 $(".operation_dept input[name=aid]").val(selectNode.data.id);
        //                 $(".operation_dept input[name=domination]").val(selectNode.data.title);
        //             }
        //
        //             layer.close(index);
        //         }
        //     });
        // });
        /**
         * 切换按钮时修改当前的value值
         */
        form.on('switch(jobSwitch)', function () {
            $(".operation_dept input[name=enterprise_status]").attr('type', 'hidden').val(this.checked ? 1 : 2);
        });
        form.on('switch(switch)', function () {
            $(".operation_dept input[name=report_status]").attr('type', 'hidden').val(this.checked ? 1 : 2);
        });
        /**
         * 用户新增修改的提交按钮
         * 通过id是否为空判断调用不同的接口
         */
        form.on('submit(submit)', function (data) {
            console.log(data);
            if (data.field.id === undefined || data.field.id === null || data.field.id === "") {
                CoreUtil.sendPost("/rpt/addAnnualReport", data.field, function (res) {
                    reloadTreeTable();
                    $(".dept-table").show();
                    $(".operation_dept").hide();
                });
            } else {
                CoreUtil.sendPut("/rpt/updateAnnualReport", data.field, function (res) {
                    reloadTreeTable();
                    $(".dept-table").show();
                    $(".operation_dept").hide();
                });
            }

            return false;
        });
        /**
         * 刷新树形数据的接口
         * @param id
         */
        var initTree = function (id) {
            var param = {deptId: id}
            CoreUtil.sendGet("/sys/dept/tree", param, function (res) {
                loadDeptTree(res.data);
            });
        };

    });
    /**
     * 设置日期
     */
    laydate.render({
        elem: '#date_of_establishment'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                startDateOfEstablishment = value.split("~")[0];
                endDateOfEstablishment = value.split("~")[1];
            } else {
                startDateOfEstablishment = null;
                endDateOfEstablishment = null;
            }

        }
    });
    laydate.render({
        elem: '#approval_date'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                startApprovalDate = value.split("~")[0];
                endApprovalDate = value.split("~")[1];
            } else {
                startApprovalDate = null;
                endApprovalDate = null;
            }

        }
    });
    laydate.render({
        elem: '#create_time'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                createStartTime = value.split("~")[0];
                createEndTime = value.split("~")[1];
            } else {
                createStartTime = null;
                createEndTime = null;
            }

        }
    });

    /**
     * 隐藏选择框
     */
    function uploadClose() {
        $(".upload-report").hide();
    }

    /**
     * 条件查询按钮方法
     */
    function search() {
        //这里以搜索为例
        tableIns2.reload({
            where: { //设定异步数据接口的额外参数，任意设
                enterpriseName: $("#enterprise_name").val(),
                socialCreditCode: $("#social_credit_code").val(),
                registrationNumber: $("#registration_number").val(),
                registrationAuthority: $("#registration_authority").val(),
                domination: $("#domination").val(),
                address: $("#address").val(),
                contactNumber: $("#contact_number").val(),
                establishStartTime: startDateOfEstablishment,
                establishEndTime: endDateOfEstablishment,
                approvalStartTime: startApprovalDate,
                approvalEndTime: endApprovalDate,
                enterpriseStatus: $("#enterprise_status").val(),
                liaisonManName: $("#liaison_man_name").val(),
                liaisonManPhone: $("#liaison_man_phone").val(),
                createStartTime: createStartTime,
                createEndTime: createEndTime,
                reportStatus: $("#report_status").val(),
                enterpriseType: $("#enterprise_type").val(),
                matching: $("#matching").val()
                // deptNo: deptNo
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    };
</script>
</body>
</html>